<?php

namespace App\Http\Controllers\User;

use Illuminate\Support\Facades\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Validator;

class CoopreationController extends Controller
{
    //
    public function getAdvicelist(){
        try{
            $chose = DB::table('advice')->get();
            return json_encode(['msg'=>1,'data' => $chose]);

        }catch (Exception $e){

            $info =  $e->getMessage().'failed line:'.$e->getLine().'failed string:'.$e->getTraceAsString();
            return json_encode(['msg'=>0,'data' => $info]);
            exit;
        }
    }

    public function addContact(){
        $data = Request::only('contact_username','contact_userposition','contact_usertel','contact_useremail','contact_content');

        $validator = Validator::make($data, [
            'contact_username' => 'required',
            'contact_userposition' => 'required',
            'contact_usertel'=> 'required|digits:11',
            'contact_useremail'=> 'required|email',
            'contact_content'=> 'required',
        ]);

        if ($validator->fails()) {
            return $validator->messages();
        }

        $data['contact_createtime'] = date('Y-m-d H:i:s');
        $result = DB::table('contact')->insert($data);
        if($result){

            return json_encode(['msg'=>1,'data' => '添加成功']);
        }
    }
}
